import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";

const router = createRouter({
    history: createWebHistory(
        import.meta.env.BASE_URL),
    routes: [{
            path: "/",
            name: "home",
            component: HomeView,
        },
        {
            path: "/cards",
            name: "cards",
            component: () =>
                import ("../views/cards.vue"),
        },
        {
            path: "/leave",
            name: "leave",
            component: () =>
                import ("../views/leave.vue"),
        },
        {
            path: "/mine",
            name: "mine",
            component: () =>
                import ("../views/Mine.vue"),
        }, {
            path: "/allService",
            name: "allService",
            component: () =>
                import ("../components/AllService.vue"),
        },
        {
            path: "/edituser",
            name: "edituser",
            component: () =>
                import ("../views/EditUser.vue"),
        }, {
            path: '/ceshi',
            component: () =>
                import ("../views/Ceshi.vue"),
        }, {
            path: '/pay',
            component: () =>
                import ("../views/Pay.vue"),
        },{
            path: '/order',
            component: () =>
                import ("../views/Order.vue"),
        },{
            path: '/news/:id',
            component: () =>
                import ("../components/NewsContent.vue"),
        },{
            path: '/addNews',
            component: () =>
                import ("../components/AddNews.vue"),
        }
    
       , {
            path: '/detail/:id',
            component: () =>
                import ("../views/Detail.vue"),
        }, {
            path: '/addview',
            component: () =>
                import ("../views/AddView.vue"),
        }, {
            path: '/work',
            component: () =>
                import ("../views/Work.vue"),
        },
        {
            path: "/userdetail",
            component: () =>
                import ("../views/UserDetail.vue"),
        },
        {
            path: "/amendpwd",
            component: () =>
                import ("../views/amendpwd.vue"),
        },
        {
            path: "/feedback",
            component: () =>
                import ("../views/feedback.vue"),
        },
        {
            path: "/addfeedback",
            component: () =>
                import ("../views/addfeedback.vue"),
        },
    ]

});
router.beforeEach((to, from, next) => {
    let token = window.localStorage.getItem("token");
    if (to.name == 'mine') next()
    if (token) next()
    if (!token) next('/mine')
})
export default router;